package com.zhentao.controller;

import com.zhentao.aop.MyLog;
import com.zhentao.classManager.dto.ClassStudentDto;
import com.zhentao.classManager.pojo.SClass;
import com.zhentao.classManager.pojo.SLevel;
import com.zhentao.classManager.pojo.vo.ClassVo;
import com.zhentao.domain.SLearningProgress;
import com.zhentao.result.Result;
import com.zhentao.service.SClassService;
import com.zhentao.service.SLearningProgressService;
import com.zhentao.service.SLevelService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/class")
public class ClassController {
    @Resource
    private SClassService classService;
    @Resource
    private SLevelService sLevelService;
    @Resource
    private SLearningProgressService sLearningProgressService;

    //查询所有班级信息
    @PostMapping("/findAll")
    public Result findAdd(@RequestBody ClassVo classVo){
       Result result = classService.selectClassAll(classVo);
        return result;
    }

    //通过班级来查询班级内的学生
    @PostMapping("/findStudentByClass")
    public Result findStudentByClass(@RequestBody ClassStudentDto studentDto){
        Result result = classService.selectStudentByClass(studentDto);
        return result;
    }

    //通过班级id查询班级信息
    @GetMapping("/findClassById/{classId}")
    public Result findClassById(@PathVariable("classId") Integer classId){
        Result result = classService.selectClassById(classId);
        return result;
    }

    //添加或修改数据
    @PostMapping("/addOrEdit")
    @MyLog(title = "班级管理",content = "添加或修改班级信息")
    public Result addOrEdit(@RequestBody SClass sClass){
        Result result = classService.classAddOrEdit(sClass);
        return result;
    }

    //批量删除
    @DeleteMapping("/deleteBatch/{classId}")
    @MyLog(title = "班级管理",content = "批量删除班级信息")
    public Result deleteBatch(@PathVariable("classId") Integer[] classId){
        Result result = classService.deleteBatchClass(classId);
        return result;
    }

    //老师查询所有
     @GetMapping("/findTeacherAll")
     public Result findTeacherAll(){
         Result result = classService.selectTeacherAll();
         return result;
     }

     //查询所有阶段
     @GetMapping("/findStageAll")
     public Result findStageAll(){
         List<SLevel> list = sLevelService.list();
         return Result.OK(list);
     }

     //班级信息导出
     @GetMapping("/download")
     @MyLog(title = "班级管理",content = "班级信息导出")
     public Result exportClass(HttpServletResponse response) throws IOException {
         classService.exportClass(response);
         return Result.OK();
     }

     //调换学生班级
    @GetMapping("/changeClass/{userId}/{classId}")
     @MyLog(title = "班级管理",content = "调换学生班级")
     public Result changeClass(@PathVariable("userId") Integer userId,@PathVariable("classId") Integer classId){
         Result result = classService.changeClass(userId,classId);
         return result;
    }

    //将学生从班级移除
     @GetMapping("/removeStudent/{userId}")
     @MyLog(title = "班级管理",content = "将学生从班级移除")
     public Result removeStudent(@PathVariable("userId") Integer userId){
         Result result = classService.removeClassStudent(userId);
         return result;
     }

     //查询具体阶段
     @GetMapping("/findStage/{stageId}")
     public Result findStage(@PathVariable("stageId") Integer stageId){
         Result result = sLearningProgressService.findStage(stageId);
         return result;
     }

     //精准查询日考班级信息
     @PostMapping("/findClassByStage")
     public Result findClassByStage(@RequestBody ClassVo classVo){
         Result result = classService.selectClassByStage(classVo);
         return result;
     }

     //导出日考信息
     @GetMapping("/downloadDay")
     @MyLog(title = "班级管理",content = "导出日考信息")
     public Result downloadDay(HttpServletResponse response) throws IOException {
         classService.downloadDay(response);
         return Result.OK();
     }
}